package com.ityj.yygh.sms.controller;

import com.ityj.yygh.result.Result;
import com.ityj.yygh.sms.service.SmsService;
import com.ityj.yygh.vo.sms.SmsVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@Api(value = "手机短信发送接口")
@RestController
@RequestMapping(path = "/api/sms")
public class SmsController {

    @Autowired
    private SmsService smsService;

    @PostMapping(path = "/sendSms/{phoneNumber}")
    public Result sendSms(@PathVariable("phoneNumber") String phoneNumber) {
        SmsVo smsVo = new SmsVo();
        smsVo.setPhone(phoneNumber);
        smsVo.setTemplateCode("1");
        Map<String, Object> param = new HashMap<>();
        // 有效时间设置1分钟
        param.put("validateTime", "1");
        smsVo.setParam(param);

        smsService.smsSend(smsVo);
        return Result.ok();
    }
}
